#include "appearance.h"
#include <QLabel>
#include <QAction>
AppearanceSettings::AppearanceSettings(QWidget *parent) : QScrollArea(parent)
{

    btn_effect=new DSwitchButton;
    slr_mask=new DSlider;
    setLineWidth(0);
    layout=new QVBoxLayout;
    layout->setMargin(0);
    QFont h1_font;
    h1_font.setPointSize(15);
    setLayout(layout);
    QLabel* title=new QLabel;
    title->setFont(h1_font);
    title->setText(tr("Appearance Setting"));
    layout->addWidget(title);

    initWindowEffect();

    loadConfig();
}

quint8 AppearanceSettings::getMask()
{
    return quint8(Settings::getValue("WindowMask").toInt());
}

void AppearanceSettings::loadConfig()
{
    int mask=Settings::getValue("WindowMask").toInt();
    slr_mask->setValue(mask);
    emit slr_mask->valueChanged(mask);
    emit btn_effect->checkedChanged(btn_effect->isChecked());
}

void AppearanceSettings::initWindowEffect()
{
    QFrame* effect_frame=new QFrame;
    QVBoxLayout* effect_layout=new QVBoxLayout;
    QHBoxLayout* effect_layout_sw=new QHBoxLayout;
    QLabel* effect_label=new QLabel;
    QLabel* mask_label=new QLabel;
    effect_layout_sw->addWidget(effect_label);
    effect_layout_sw->addWidget(btn_effect);
    effect_layout->addLayout(effect_layout_sw);
    effect_layout->addSpacing(10);
    effect_layout->addWidget(mask_label);
    effect_layout->addWidget(slr_mask);
    slr_mask->setMaximum(255);
    slr_mask->setMinimum(0);
    effect_label->setText(tr("Window Effect"));
    effect_label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
    mask_label->setText(tr("Transparency"));
    mask_label->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
    effect_frame->setLayout(effect_layout);
    effect_frame->setLineWidth(0);
    effect_frame->setAutoFillBackground(true);
    layout->addWidget(effect_frame);
    layout->addStretch();
    connect(btn_effect,&DSwitchButton::clicked,[=](bool open){
        emit EffectChange(open,quint8(slr_mask->value()));
    });
    connect(btn_effect,&DSwitchButton::checkedChanged,[=](bool open){
        if(open){
            slr_mask->show();
            mask_label->show();
        }else {
            slr_mask->hide();
            mask_label->hide();
        }
    });
    connect(slr_mask,&DSlider::valueChanged,[=](int value){
        emit EffectChange(btn_effect->isChecked(),quint8(value));
        Settings::setValue("WindowMask",QString::number(value));
    });
}
